<template>
	<view class="content yaoqingaddindex pB50">
		<view class="input-group">			

			<!-- <view class="input-row f14 border">
				<text class="title">到访时间：</text>
				<view class="tab"  >{{ thistimes }}</view>
			</view> -->
			
			
			<view class="input-row f14 border">
				<text class="title" >到访公司：</text>
				<view  class="tab w70" v-bind:class="{ active: isActive }" @click="open('company')">{{companyInfodept?companyInfodept:'请填写到访公司'}}</view>			
				<!-- <m-input v-if="comdeptlist.length==0" type="text" class="f14" readonly="readonly" clearable v-model="choosecompany"  placeholder="请填写到访公司"></m-input>				 -->
				<view class="">
					<uni-icons type="arrowright" size="20"></uni-icons>
				</view>
			</view>
			<view class="input-row f14 border">
				<text class="title">到访部门：</text>
				<view  class="tab w70" v-bind:class="{ active: isActive }" @tap="toggleTab('selector')">{{ resultInfodept.result}}</view>
			
				<!-- <m-input @click="inputstate" v-if="deptlist.length==0" type="text" class="f14" readonly clearable v-model="address"  placeholder="请填写到访部门"></m-input>				 -->
				<view class="">
					<uni-icons type="arrowright" size="20"></uni-icons>
				</view>
			</view>
			<view class="input-row f14 border">
				<text class="title">到访日期：</text>
				<!--  <m-input type="text" @focus="toggleTab('date')" clearable v-model="resultInfo.result" placeholder="请选择到访时间"></m-input> -->
				<!-- <view class="tab" v-bind:class="{ active: isActive }" @tap="toggleTab('date')">{{ resultInfo.result}}</view> -->
				<view class="tab w70" v-bind:class="{ active: isActive }" @tap="toggleTab('date')">{{ resultInfo.result}} <span class="f12 pL5" v-if="resultInfo.result != '请选择到访日期'">（{{nowweek}}）</span></view>
				<view class="">
					<uni-icons type="arrowright" size="20"></uni-icons>
				</view>
			</view>
			
			<view class="input-row f14 border">
				<text class="title">到访开始：</text>
				<view class="tab w70" v-if="!companyid" @click="inputstate()"  v-bind:class="{ active: isActive }" >请选择到访开始时间</view>
				<!-- start="08:00" end="19:00" -->
				<picker mode="time" class="w70" v-if="companyid" :value="time"  @change="bindTimeChange">
					<view class="tab"  v-bind:class="{ active: isActive }">{{time?time:'请选择到访开始时间'}}</view>
				</picker>
				<view class="">
					<uni-icons type="arrowright" size="20"></uni-icons>
				</view>
			</view>
			
			<view class="input-row f14 border">
				<text class="title">到访结束：</text>
				<view class="tab w70" v-if="!companyid" @click="inputstate()"  v-bind:class="{ active: isActive }" >请选择到访结束时间</view>
				
				<picker mode="time" class="w70" v-if="companyid" :value="timeend"  @change="bindTimeChangeend">
					<view class="tab"  v-bind:class="{ active: isActive }">{{timeend?timeend:'请选择到访结束时间'}}</view>
				</picker>
				<view class="">
					<uni-icons type="arrowright" size="20"></uni-icons>
				</view>
			</view>
			<view class="border input-row f14">
				<!-- <view style="padding-left: 15px;padding-top: 5px;">到访事由：</view> -->
					<text class="title">车牌号码：</text>
					<view class="uni-textarea tab w70" v-if="companyid">
					<!-- <textarea  @click="inputstate()" auto-height v-model="carnumber" placeholder="车牌号码" /> -->
					<!-- <m-input @click="inputstate"  type="text" class="f14"  clearable v-model="carnumber"  placeholder="请填写车牌号码"></m-input> -->
					 <view class="radioall">
						<label class="radio" @click="chooseradio('1')"><radio value="r1"  :checked="radiostate==='1'" />没有</label>
						<label class="radio mL10" @click="chooseradio('2')"><radio value="r2"  :checked="radiostate==='2'" />有</label>
						<div class="w50 inline-block vm pL5" v-if="radiostate==='2'">
							<!-- <m-input @click="inputstate"  type="text" class="f14"  clearable v-model="carnumber"  placeholder="请填写车牌号码"></m-input> -->
							<input type="text" class="f14 pL5 fangcarnumbers"  @click="inputstate" v-model="carnumber" placeholder="请填写车牌号码" />
	
						</div>
						
					</view>
					</view>
					<view class="tab w70" v-if="!companyid" @click="inputstate()"  v-bind:class="{ active: isActive }" >请填写车牌号码</view>
						
			</view>
			<view class="border input-row f14">
				<!-- <view style="padding-left: 15px;padding-top: 5px;">到访原由：</view> -->
					<text class="title">到访原由：</text>
				<view class="uni-textarea tab w70" v-if="companyid">
					<!-- <textarea  @click="inputstate()" auto-height v-model="yuanyou" placeholder="请填写到访缘由" /> -->
					<input type="text" class="f14 fangshowyuanyou"  @click="inputstate()" v-model="yuanyou"  placeholder="请填写到访原由" />


					<!-- <m-input  type="text" class="f14" clearable  @click="inputstate()" v-model="yuanyou"  placeholder="请填写到访原由"></m-input> -->
				</view>
					<view class="tab w70" v-if="!companyid" @click="inputstate()"   v-bind:class="{ active: isActive }" >请填写到访原由</view>
						
			</view>
			<!-- <view class="border input-row f14">
					<view class="pL15 p10">
						
						<span class='smbtnadd' v-if="!addfcur" @click='showaddfcur'>添加随访人员</span>
						<span class='smbtnadd' v-if="addfcur" @click='hideaddfcur'>不添加随访人员</span>
					</view>	
			</view> -->
			
			<view class="border p10 pL15 pR15 f14" v-if="addfcur">				
					<text class="title">随访人员</text>
				<view class="uni-textarea tab " >
					<view class="title2 borderb1 flex pT5 pB5">
						<text class='w40 pL5'>姓名</text>
						<text class='w50 pL5'>身份证号码</text>
						<text class='w30 tRight'>操作</text>
					</view>
					<view class="listall">
						<view class="tCenter borderb1 p5 col_999" v-if='userlist.length==0'>
							暂无数据
						</view>
						<view class="usrlist borderb1 flex pT5 pB5" v-for="(item,index) in userlist">
							<text class='w40 pL5'>{{item.fname}}</text>
							<text class='w50 pL5'>{{item.fidentitycard | isidcard}}</text>
							<text class='w30 tRight'><span class='smbtn smbtn_red' @click="deluser(index,item.fid)">删除</span></text>
						</view>
					</view>
					<view class="usrlist borderb1 flex pT5 pB5" v-if="showinput">
						<view class="w40">
							<m-input type="text" class="f14 w80 borderall "  clearable v-model="sm_name"  placeholder="姓名"></m-input>
						</view>
						<view class="w50">
							<m-input type="text" class="f14 w80 borderall"  clearable v-model="sm_idcard"  placeholder="身份证号码"></m-input>
						</view>
						
						<text class='w30 tRight'><span class='smbtn mR5' @click='hideinput'>取消</span> <span class='smbtn' @click='addarrinput'>确定</span></text>
					</view>
					<view class="add tCenter pT5 pB5">
							<uni-icons type="plus" color="#34ce78" size="24"></uni-icons>
							<text class="pL2" style="color:#34ce78" @click="addshowinput">添加</text>
					</view>
				</view>
						
			</view>
			<!-- <view class="border f14">
				<view style="padding-left: 15px;padding-top: 5px;">请在下面填写备注：</view>
				<view class="uni-textarea" style="padding-top: 5px;"><textarea auto-height v-model="beizhu" placeholder="请填写备注" /></view>
			</view> -->
		</view>
		<view class="btn-row w70 mauto" ><button type="primary" class="primary f16" @click="demo.submitadds">确定提交</button></view>
		<!-- <view class="btn-row w70 mauto" v-if="!statein"><button type="primary" class="primary2 ">二维码已过期</button></view> -->
				<w-picker
			        :visible.sync="date3visible"
			        mode="selector"
			        value=""
			        default-type="name"
			        :default-props="defaultProps"
			        :options="deptlist"
			        @confirm="onConfirm($event,'selector')"
			        @cancel="onCancel"
			        ref="selector" 
			    ></w-picker>
					<w-picker
						:visible.sync="date1visible"
						mode="date" 
						startYear="2020" 
						endYear="2030"
						:value="showyearin"
						:current="false"
						fields="day"
						@confirm="onConfirm($event,'date')"
						@cancel="onCancel"
						:disabled-after="false"
						ref="date" 
					></w-picker>
					
					    <w-picker
					        :visible.sync="date2visible"
					        mode="time" 
					        value=""
					        :current="false"
					        :second="true"
					        @confirm="onConfirm($event,'time')"
					        @cancel="onCancel"
					        ref="time" 
					    ></w-picker>
						
				<!-- <w-picker
				    :visible.sync="date3visible"
				    mode="selector"
				    value=""
				    default-type="name"
				    :default-props="defaultProps"
				    :options="comdeptlist"
				    @confirm="onConfirm($event,'company')"
				    @cancel="onCancel"
				    ref="company" 
				></w-picker> -->
				
				
				
				<view class="drawer" v-if="isshow">
					<view class="setbox" :class="{show: isshow}">
						<view class="header">
							<view class="drawer-item">
								<view style="font-weight: bold;margin: 0 auto;">选择公司</view>
								<view class="p5" @click="close()">
									关闭
								</view>
							</view>
							<view class="drawer-list-item">
								<view >
									<!-- <uni-search-bar placeholder="请输入公司" v-model="inputsearchVal" @confirm="search()"></uni-search-bar> -->
									<view class="w90 mauto p5 flex borderall">
										<m-input class="w100" type="text" focus clearable v-model="inputsearchVal" placeholder="请输入公司"  @change="search()"></m-input>
									</view>
								
								 <view class="comdeptlist p10">
								 	<view class="lsit  overflow mT5 pB5" v-for="item in comdeptlist">
								 		<text>{{item.name}}</text>
								 		<text class=" choobtn col_white borderr8 p2 pL5 pR5 f12" @click="choosecom(item)">选择</text>
								 	</view>
									<view class="p10 tCenter" v-if="comdeptlist.length==0"> 
										暂未找到对应的公司
									</view>
									
								 </view>
								</view>
							</view>
						</view>
					</view>
				</view>
		<backnext></backnext>
		<!-- 底部导航 -->
		<footernav pagePath='myyuyue'></footernav>
		<!-- 加载动画 -->
		<loading v-if="!isloading()"></loading>
	</view>
</template>
<script module="demo" lang="renderjs">
	 export default {
		 methods: {
			
			 submitadds:function(event, ownerInstance){
			 	// document.getElementsByTagName("input")[0].value
			 	
			 
			 	 if(document.getElementsByClassName("fangshowyuanyou").length>0){
					 var vale2=document.getElementsByClassName("fangshowyuanyou")[0].childNodes[0].childNodes[1]._value;
					 var newvale2=vale2
				 }else{
					var newvale2=''; 
				 }
				 
				 if(document.getElementsByClassName("fangcarnumbers").length>0){
					 var vale=document.getElementsByClassName("fangcarnumbers")[0].childNodes[0].childNodes[1]._value;
				 	 var newvale=vale
				 }else{
				 	var newvale=''; 
				 }
				 
				 let temp={vale:newvale,vale2:newvale2,
			 	 };
			 	  ownerInstance.callMethod('register',temp);
			  },
		},
	}
</script>
<script>
import mInput from '@/components/m-input.vue';
import wPicker from '@/components/w-picker/w-picker.vue';
import {addappointment,meetingflist,meetingfcur} from '@/common/api/appointment.js';
import {showgetlist} from '@/common/api/department.js'
import {userinfo,codescancode} from '@/common/api/user.js'; 
import {thistimestampToTime} from "@/common/common.js"
 import {conpanysearch} from '@/common/api/pool.js'
export default {
	components: {
		mInput,
		wPicker
	},
	data() {
		return {
			radiostate:'',
			addfcur:false,
			inputsearchVal:'',
			carnumber:'',
			sm_idcard:'',
			sm_name:'',
			showinput:false,
			userlist:[],
			date1visible:false,
			date2visible:false,
			date3visible:false,
			thiscode:"",
			defaultProps:{
					label:"name",
					value:"id"
				},
				
			defaultProps2:{
					label:"name",
					value:"id"
				},
			deptlist:[],
			comdeptlist:[],
			companyid:'',
			deptid:'',
			page:1,
			time:"",
			timeend:'',
			pagesize:9999,
			dept_name:"",
			account: '',
			password: '',
			address: '',
			choosecompany:'',
			yuanyou: '',
			beizhu: '',
			company:'',
			isActive: true,
			statein:true,
			showyearin:"2020",
			showyearinend:"2030",
			resultInfo: {
				result: '请选择到访日期',
			},
			resultInfotime: {
				result: '请选择到访时间',
				resultend: '请选择到访时间'
			},
			resultInfodept: {
				result: '请选择到访部门'
			},
			companyInfodept: '请选择到访公司',
			thistimes:"",
			isshow:false,
			clickstate:true,
			visittime:"",
			member_frequency:0,
			userdata:'',
			weeks:["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
			nowweek:'',
			
		};
	},
	onLoad(event) {
		
		if(event.code){
			this.thiscode=event.code;
		}		
		var thisdata=new Date();
		var thisyear=thisdata.getFullYear();
		this.showyearin=thisyear;//获取当时时间年
		this.showyearinend=thisyear+5;
		
		var thistimes=thisdata.getTime();
		this.thistimes=thistimestampToTime(thistimes);
		// codescancode({icp_sn:this.thiscode}).then(res=>{//获取用户信息
		// // console.log(res)
		// 	if(res.data.code==200){
		// 		if(res.data.data.incompanylist.length>0){
		// 			console.log(JSON.stringify(res.data.data.incompanylist))
		// 			this.comdeptlist=res.data.data.incompanylist;
					
		// 			console.log(this.comdeptlist)
						
		// 		 }
			
		// 	}else{
		// 		uni.showToast({
		// 			icon: 'none',
		// 			title: res.data.message
		// 		});
		// 		this.statein=false;
		// 	}		
		// })
		
		userinfo({}).then(res=>{//获取用户信息		
			
			if(res.data.member.member_frequency){
				this.member_frequency=res.data.member.member_frequency;				
			}
			this.userdata=res.data.data;
			if(res.data.member.member_frequency==0){
				uni.showToast({
					icon: 'none',
					title: '积分为0，请充值后再操作'
				});
				uni.reLaunch({
				    url: '/pages/user/user'
				});
				return;
			}
				
		})
		
		this.getdeptlist()
	},
	onShow() { 
		// this.getdeptlist()
		
		},
	watch: {
	   inputsearchVal(newName, oldName) {
			this.showcomlist()
	     }
	   },	
	methods: {
		chooseradio(type){
			this.radiostate='';
			this.radiostate=type;
			console.log(this.radiostate)
		},
		showaddfcur(){
			this.showuserlist();
			this.addfcur=true;
		},
		hideaddfcur(){
			this.userlist=[];
			this.addfcur=false;
		},
		deluser(index,id){
			// this.userlist.splice(index,1);
			let obj={
				fid:id,
				type:'d',
			}
			meetingfcur(obj).then(res=>{//获取用户信息
			// console.log(res)
				if(res.data.code==200){
					this.showuserlist();
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
				}else{
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
					this.statein=false;
				}		
			})
			
		},
		addshowinput(){
			this.showinput=true;
		},
		hideinput(){
			this.sm_name='';
			this.sm_idcard='';
			this.showinput=false;
		},
		showuserlist(){
			this.userlist=[];
			meetingflist({}).then(res=>{//获取用户信息
			// console.log(res)
				if(res.data.code==200){
					if(res.data.data.length>0){
						// console.log(JSON.stringify(res.data.data))
						this.userlist=res.data.data;
							
					 }
				
				}else{
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
					this.statein=false;
				}		
			})	
		},
		
		addarrinput(){
			if(!this.sm_name){
				uni.showToast({
					icon: 'none',
					title: '请输入随访人姓名'
				});
			}else if(!this.sm_idcard){
				uni.showToast({
					icon: 'none',
					title: '请输入随访人身份证号'
				});
			}else if(this.sm_idcard.length!=18){
				uni.showToast({
					icon: 'none',
					title: '请输入正确的随访人身份证号'
				});
			}else{
				var obj={
					fname:this.sm_name,
					fidentitycard:this.sm_idcard,
					type:'c',
				}
				meetingfcur(obj).then(res=>{//获取用户信息
			// console.log(res)
				if(res.data.code==200){
					this.showuserlist();
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
				}else{
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
					this.statein=false;
				}		
			})	
				// this.userlist.push(obj)
				this.hideinput();
			}
		},
		choosecom(item){
			this.companyid=item.id;
			this.companyInfodept=item.name;
			this.getdeptlist();			
			this.isshow = false;
			var dateTime=new Date();
			var y=dateTime.getFullYear();		
			dateTime=dateTime.setDate(dateTime.getDate()+1);
			dateTime=new Date(dateTime);
			var M = (dateTime.getMonth()+1 < 10 ? '0'+(dateTime.getMonth()+1) : dateTime.getMonth()+1) ;			 
			var D = (dateTime.getDate() < 10 ? '0'+(dateTime.getDate()) : dateTime.getDate());
			var newtimes=y+'-'+M+'-'+D;
			var day = dateTime.getDay();
			this.nowweek = this.weeks[day];
			this.showyearin=newtimes;//获取当时时间年
			this.resultInfo.result=newtimes;//获取当时时间年
		},
		showcomlist(){
			this.comdeptlist=[];
			conpanysearch({'name':this.inputsearchVal,type:'viss'}).then(res=>{//获取用户信息
			// console.log(res)
				if(res.data.code==200){
					if(res.data.data.length>0){
						// console.log(JSON.stringify(res.data.data))
						this.comdeptlist=res.data.data;
							
					 }
				
				}else{
					uni.showToast({
						icon: 'none',
						title: res.data.message
					});
					this.statein=false;
				}		
			})	
		},
		close() {
			// console.log('213')
			this.isshow = false
		 },
		open(){
			this.isshow = true
		},
		search(){
			
		},
		toggleTab(str) {
			console.log(str)
			// if(!this.statein){
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '二维码已过期，请重新扫码'
			// 	});
			// 	return;
			// }
			if(this.companyInfodept=='请选择到访公司'){
				uni.showToast({
					icon: 'none',
					title: '请优先选择公司'
				});
				return;
			}
			if(str=='selector'){
				if(this.companyid){
					this.getdeptlist();
					this.$refs[str].show()
				}else{
					uni.showToast({
						icon: 'none',
						title: '请优先选择公司'
					});
				}
				
			}else{
				this.$refs[str].show()
			}
			
			console.log(this.comdeptlist)
		},
		onCancel(res,val){
		/*业务逻辑*/
		},
		bindTimeChange: function(e) {
			var times=e.detail.value
			var timearr = times.split(':'); 
			
			if(Number(timearr[0])<8){
				uni.showToast({
					icon: 'none',
					title: '请在当天上午8：00之后进行预约'
				});
				return;
			}else if(Number(timearr[0])<=8&&Number(timearr[1])>0){
				uni.showToast({
					icon: 'none',
					title: '请在当天上午8：00之后进行预约'
				});
				return;
			}
			
			if(Number(timearr[0])>=18&&Number(timearr[1])>0){
				uni.showToast({
					icon: 'none',
					title: '请在当天下午18：00之前进行预约'
				});
				return;
			}
			
			// if(this.timeend){
			// 	var timesthis=Number(times.replace(':',''));
			// 	var timesold=Number(this.timeend.replace(':',''));	
					
			// 	if(timesthis>=timesold){
			// 		uni.showToast({
			// 			icon: 'none',
			// 			title: '预约开始时间不能高于预约结束时间'
			// 		});
			// 		return;
			// 	}
			// }
			this.time = e.detail.value
			this.resultInfotime.result = e.detail.value;
						
			// if(!this.timeend){
				// var newhour=Number(timearr[0])+1+':'+timearr[1];
				// var hour2=(Number(timearr[0])+1)>10?Number(timearr[0])+1:'0'+Number(timearr[0])+1;
				if((Number(timearr[0])+1)>=10){
					var hour2=Number(timearr[0])+1;
				}else{
					var hour2='0'+(Number(timearr[0])+1);
				}
				var newhour=hour2+':'+timearr[1];
				console.log(newhour)
				this.timeend = newhour
				this.resultInfotime.resultend = newhour
			// }
			
		},
		bindTimeChangeend: function(e) {
			var times=e.detail.value
			var timearr = times.split(':'); 
			if(Number(timearr[0])<=8&&Number(timearr[1])>0){
				uni.showToast({
					icon: 'none',
					title: '请在当天上午8：00之后进行预约'
				});
				return;
			}
			if(Number(timearr[0])>=19&&Number(timearr[1])>0){
				uni.showToast({
					icon: 'none',
					title: '请在当天下午19：00之前进行预约'
				});
				return;
			}
			
			
			
			if(this.time){
				var timesthis=Number(times.replace(':',''));			
				var timesold=Number(this.time.replace(':',''));	
					
				if(timesthis<=timesold){
					uni.showToast({
						icon: 'none',
						title: '预约结束时间不能低于预约开始时间'
					});
					return;
				}
			}
			this.timeend = e.detail.value
			this.resultInfotime.resultend = e.detail.value;			
			if(!this.time){
				
				// var newhour=Number(timearr[0])-1+':'+timearr[1];
				if((Number(timearr[0])-1)>=10){
					var hour2=Number(timearr[0])-1;
				}else{
					var hour2='0'+(Number(timearr[0])-1);
				}
				var newhour=hour2+':'+timearr[1];
				console.log(newhour)
				this.time = newhour
				this.resultInfotime.result = newhour;
			}
			
		},
					
		onConfirm(res,val) {
			// console.log(res)
			// console.log(val);
			//如果页面需要调用多个mode类型，可以根据mode处理结果渲染到哪里;
			switch (val) {
				case 'date':
					this.resultInfo.result = res.value;
					var dateTime=new Date(res.value);
					var day = dateTime.getDay();
					this.nowweek = this.weeks[day];
					
					break;
				case 'time':
					this.resultInfotime.result = res.value
					break;
				case 'selector':
					this.resultInfodept.result = res.result
					this.address = res.result
					this.deptid =res.value
					break;
				case 'company':
					this.companyInfodept = res.result
					this.choosecompany = res.result
					this.companyid =res.value
					break;
					
					
			}
			// this.resultInfo = { ...val };
			// this.isActive = false;
		},
		inputstate(){
			if(this.companyInfodept=='请选择到访公司'){
				uni.showToast({
					icon: 'none',
					title: '请优先选择公司'
				});
				return;
			}
		},
		showcarnumber(){
			this.carnumber=this.carnumber;
		},
		
		showyuanyou(){
			this.yuanyou=this.yuanyou;
		},
		register(item) {
			this.carnumber=item.vale;
			this.yuanyou=item.vale2;
				if(this.clickstate){
					this.clickstate=false;
					setTimeout(()=>{
						this.clickstate=true;
					},2000)
			if(!this.companyid){				
				uni.showToast({
					icon: 'none',
					title: '请选择到访公司'
				});
				return;
			}
			if(this.companyid==this.userdata.companyid){
				uni.showToast({
					icon: 'none',
					title: '访客不能选择自己的公司'
				});
				return;
			}	
			if (this.resultInfo.result == '请选择到访日期') {
				uni.showToast({
					icon: 'none',
					title: '请选择到访日期'
				});
				return;
			}
			if (this.resultInfotime.result == '请选择到访时间') {
				uni.showToast({
					icon: 'none',
					title: '请选择到访时间'
				});
				return;
			}
			
			this.visittime = this.resultInfo.result +" "+ this.resultInfotime.result;
			
			this.visittimeend = this.resultInfo.result +" "+ this.resultInfotime.resultend;
			var datex = new Date(this.visittime);
			var time1 = datex.getTime();
			console.log(time1);
			
			var datexx = new Date();
			var time2 = datexx.getTime();
			console.log("time check ")
			console.log(time1)
			
			console.log(time2);
					
			if(time1<=time2){
				uni.showToast({
					icon: 'none',
					title: '请选择正确的时间'
				});
				return;
			}
			
			if (this.address.length == 0) {
				uni.showToast({
					icon: 'none',
					title: '请选择到访部门'
				});
				return;
			}
			if (this.radiostate == '') {
				uni.showToast({
					icon: 'none',
					title: '请选择到车牌号码类型'
				});
				return;
			}
			if (this.radiostate=='2'&&this.carnumber=='') {
				uni.showToast({
					icon: 'none',
					title: '请填写车牌号码'
				});
				return;
			}
			
			if (this.radiostate=='2'&&this.carnumber.length<7||this.radiostate=='2'&&this.carnumber.length>8) {
			
				uni.showToast({
					icon: 'none',
					title: '请填写正确的车牌号码'
				});
				return;
			}
			
			// if (this.carnumber.length == 0) {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请填写车牌号码'
			// 	});
			// 	return;
			// }
			
			if (this.yuanyou.length == 0) {
				uni.showToast({
					icon: 'none',
					title: '请填写到访原由'
				});
				return;
			}
			
			if (this.yuanyou.length >12) {
				uni.showToast({
					icon: 'none',
					title: '您填写的原由超出12个字，请处理'
				});
				return;
			}
			// if (this.beizhu.length == 0) {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		title: '请填写备注'
			// 	});
			// 	return;
			// }
				
				if(this.userlist){
					var newuserlist=JSON.stringify(this.userlist);
				}else{
					var newuserlist='';
				}
				
				addappointment({
					"visittime": this.visittime,
					"visittime2": this.visittimeend,
					"carnumber":this.carnumber,
					"fdata":newuserlist,
					"address": this.address,
					"deptid":this.deptid,
					"reson": this.yuanyou,
					"companyid":this.companyid,
					 "type":'viss',
					"remark": this.beizhu,
				}).then(res=>{
					console.log(res)
					if (res.data.code == 200) {
					// uni.showToast({
					// 	title: res.data.message,
					// 	icon: 'none',
					// 	duration: 2000
					// });
					
		// 			uni.navigateTo({
		// 				url: '/pages/yaoqing/xiangqing?sharebtn=YES&detailDate=' + encodeURIComponent(JSON.stringify(detail))
		// 			});
					uni.reLaunch({
						url:'/pages/shouquan/successful'
					});
					this.resultInfo.result = '请选择到访日期';
					this.resultInfotime.result= '请选择到访时间';
		
					this.address = '';
					this.yuanyou = '';
					this.beizhu = '';
				} else {
					// uni.showToast({
					// 	title: res.data.message,
					// 	icon: 'none',
					// 	duration: 2000
					// });
					uni.showModal({
						title: '',
						content: res.data.message,						
						showCancel:false,
						confirmText: "确定",
						success: function (res) {
							if (res.confirm) {
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
				})
				}
				
		},
		getdeptlist(){
			showgetlist({
				companyid:this.companyid,
				page:this.page,
				pagesize:this.pagesize,
				type:'link',
			}).then(res=>{
			
				this.deptlist = res.data.data
				
			})
			console.log(this.deptlist)
		},
		/*选择部门*/
		deptPickerChange(){
			
		},
	}
};
</script>

<style scoped>
.usrlist .m-input-view{width: 85%;}
.yaoqingaddindex .uni-input-placeholder{font-size: 14px;}
.tab {
	line-height: 39px;
}
.content {
	display: flex;
	flex: 1;
	flex-direction: column;
	background-color: #efeff4;
}
.active {
	color: #747272;
}
.uni-textarea uni-textarea {
	padding-left: 0%;
	width: 94%;
}
.primary{
	background: #007aff;                                                                                                                                                      
}
.primary2{
	background: #747272;
}
.smbtn{padding: 2px 5px;background: #007aff;font-size: 12px;color: white;border-radius: 5px;}
.smbtnadd{padding: 5px 8px;background: #007aff;font-size: 12px;color: white;border-radius: 5px;}
.smbtn_red{background: #ff0000;}
.navName{
		width: 95%;
		margin: 10px auto;
		background: #FFFFFF;
	}
	.choiceNav{
		width: 95%;
		margin: 0 auto;
		height: 40px;
		display: flex;
		font-size: 14px;
		line-height: 40px;
		justify-content: space-between;
	}
	.drawer {
	  width:100%;
	  display:flex;
	  display:-webkit-flex;
	  flex-direction:column; 
	}
	.setbox{
	    position:fixed;
	    z-index:1000;
	    left:0px;
	    right:0px;
	    width:100%;
	    height:100%;
	    background:rgba(51,51,51,0.4);
	    border-left: 1px solid #CFD8DC!important;
	    box-shadow:0px 3px 12px rgba(0,0,0,0.12);
	    -webkit-transition: all 0.3s ease;
	    transition: all 0.3s ease;
	    bottom:-100%;
	}
	.show {
	 bottom: 0;
	}
	.header{
		width: 100%;
		background: #FFFFFF;
		line-height: 40px;
		position: absolute;
		height: 20rem;
		bottom: 0;
		 border-top-left-radius: 5px;
		 border-top-right-radius: 5px;
		 border-bottom: 10px solid #FFFFFF;
	}
	
	.drawer-list-item{
		width: 100%;
		height: 40px;
		border-bottom: 1px solid #EEEEEE;
	}
	
	.drawer-item{
		width: 95%;
		margin: 0 auto;
		display: flex;
		justify-content: space-between;
		font-size: 14px;
		color: #333333;
	}
	.uni-searchbar{width: 100%;}
	.comdeptlist{height: 14rem;overflow: auto;}
	.comdeptlist .lsit{border-bottom: 1px solid #C0C0C0;}
	.choobtn{background-color: #2a82e4;    float:right ;}
	.input-row{align-items: center;}
</style>
